//
//  YiLouController.m
//  民族文化宫
//
//  Created by WANG CUNRUI on 14-6-7.
//  Copyright (c) 2014年 WANG CUNRUI. All rights reserved.
//

#import "YiLouController.h"

@interface YiLouController () <UIPopoverControllerDelegate>
@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UIPopoverController *popover;
@property CGFloat lastRotation;
@property CGRect frame;
@property (strong, nonatomic) UIButton *button1;
@property (strong, nonatomic) UIButton *button2;
@property (strong, nonatomic) UIButton *button3;
@property (strong, nonatomic) UIButton *button4;
@end

@implementation YiLouController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self.view setBackgroundColor:[UIColor whiteColor]];

//    CGRect frame = self.view.bounds;
//    CGSize f = frame.size;
//    CGFloat h = f.height;
//    CGFloat w = f.width;
//    self.imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"112.jpg"]];
//    self.imageView.frame  = CGRectMake(0, 0, w, h-110);
//    [self.view addSubview:self.imageView];
    _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button1.frame = CGRectMake(82, 124, 25, 25);
    [_button1 setBackgroundColor:[UIColor blackColor]];
    [_button1 addTarget:self action:@selector(butClick1:) forControlEvents:UIControlEventTouchUpInside];
    _button1.tag = 1;
    [self.view addSubview:_button1];
    _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button2.frame = CGRectMake(78, 257, 25, 25);
    [_button2 setBackgroundColor:[UIColor clearColor]];
    [_button2 addTarget:self action:@selector(butClick2:) forControlEvents:UIControlEventTouchUpInside];
    _button2.tag = 1;
    [self.imageView addSubview:_button2];
    _button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button3.frame = CGRectMake(213, 105, 25, 25);
    [_button3 setBackgroundColor:[UIColor clearColor]];
    [_button3 addTarget:self action:@selector(butClick3:) forControlEvents:UIControlEventTouchUpInside];
    _button1.tag = 1;
    [self.imageView addSubview:_button3];
    _button4 = [UIButton buttonWithType:UIButtonTypeCustom];
    _button4.frame = CGRectMake(249, 225, 25, 25);
    [_button4 setBackgroundColor:[UIColor clearColor]];
    [_button4 addTarget:self action:@selector(butClick4:) forControlEvents:UIControlEventTouchUpInside];
    _button4.tag = 1;
    [self.imageView addSubview:_button4];
    
}

- (void)butClick1:(UIButton *)but
{
    CGPoint point = CGPointMake(95, 124);
    _popView = [[MZdetail alloc]initWithFrame:CGRectMake(90, 124, 80, 30)];
    
    [self initWithCoordinateInPoint:point Inview:self.view withContentView:_popView delegate:self];
    [self detail:nil tag:0];
    
}

-(void)initWithCoordinateInPoint:(CGPoint)point Inview:(UIView*)view withContentView:(UIView *)cView delegate:(id<PopoverViewDelegate>)delegate
{
    
    [PopoverView showPopoverAtPoint:point inView:view withContentView:cView delegate:delegate];
    
}

- (void)popoverControllerDidPresentPopover:(WYPopoverController *)controller
{
    NSLog(@"popoverControllerDidPresentPopover");
}

- (BOOL)popoverControllerShouldIgnoreKeyboardBounds:(WYPopoverController *)popoverController
{
    return YES;
}

- (void)butClick2:(UIButton *)but
{

}

- (void)butClick3:(UIButton *)but
{

}
- (void)butClick4:(UIButton *)but
{

}

- (void)showPopover
{
    CGRect frame = self.view.bounds;
    _popover = [UIPopoverController alloc];
    _popover.popoverContentSize = CGSizeMake(100, 100);
    [_popover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    _popover.backgroundColor = [UIColor blackColor];
//    [self.view addSubview:_popover.version];

}

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
//    self.enabled = YES;
    
    // popover被销毁的时候，移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return  YES;
}

-(void)detail:(MZdetail *)detail tag:(int)tag
{
    _ZLdetailController = [[MZZLdetailViewController alloc]init];
    if (tag == 1) {
        [self.navigationController pushViewController:_ZLdetailController animated:YES];
    }
}

@end
